/*
ID: simplyz2
LANG: C
TASK: crypt1
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 9
int num, digits[MAX_LEN];
int flag[MAX_LEN];
int total;

void
brute_force()
{
	int a, b, c, d, e;
	int first, second, tmp1, tmp2, value;
	for(a=0; a<num; a++)
		for(b=0; b<num; b++)
			for(c=0; c<num; c++)
				for(d=0; d<num; d++)
					for(e=0; e<num; e++) {
						first = digits[a]*100 + digits[b]*10 + digits[c];
						second = digits[d]*10 + digits[e];
						value = first * second;
						tmp1 = first * digits[d];
						tmp2 = first * digits[e];
						if(value>9999 || value<1000 || !flag[value%10] || !flag[(value/10)%10] || !flag[(value/100)%10] || !flag[(value/1000)%10])
							continue;
						if(tmp1>999 || tmp1<100 || !flag[tmp1%10] || !flag[(tmp1/10)%10] || !flag[(tmp1/100)%10])
							continue;
						if(tmp2>999 || tmp2<100 || !flag[tmp2%10] || !flag[(tmp2/10)%10] || !flag[(tmp2/100)%10])
							continue;
						++total;
					}
}

int
main(int argc, char **argv)
{
	int i;
	freopen("crypt1.in", "r", stdin);
	freopen("crypt1.out", "w", stdout);
	while(scanf("%d", &num) != EOF) {
		total = 0;
		memset(flag, 0, sizeof(flag));
		for(i=0; i<num; i++) {
			scanf("%d", digits+i);
			flag[digits[i]] = 1;
		}
		brute_force();
		printf("%d\n", total);
	}
	return 0;
}
